package com.yuan.yblog.portal.pojo.VO;

import com.yuan.yblog.crud.entity.UserMessage;
import com.yuan.yblog.portal.pojo.contants.Status;
import com.yuan.yblog.portal.pojo.contants.UserMessageStatus;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.Date;

/**
 *  UserMessage的子类，用于简略展示用户消息
 */
@EqualsAndHashCode(callSuper = true)
@Data
@Schema(description = "用户消息类型VO")
public class UserMessageVO extends UserMessage {

    @Schema(description = "消息来源者昵称")
    private String fromUserName;

    @Schema(description = "消息来源者昵称")
    private String toUserName;

    @Schema(description = "消息类型标识")
    private String userMessageKey;

    public static UserMessageVO getUserMessageVO(UserMessage userMessage){
        UserMessageVO vo = new UserMessageVO();
        vo.setId(userMessage.getId());
        vo.setFromUserId(userMessage.getFromUserId());
        vo.setToUserId(userMessage.getToUserId());
        vo.setPostId(userMessage.getPostId());
        vo.setCommentId(userMessage.getCommentId());
        vo.setContent(userMessage.getContent());
        vo.setMessageType(userMessage.getMessageType());
        vo.setCreated(userMessage.getCreated());
        vo.setModified(userMessage.getModified());
        vo.setStatus(userMessage.getStatus());
        return vo;
    }

    public UserMessage toUserMessage(){
        UserMessage userMessage = new UserMessage();
        userMessage.setId(this.getId());
        userMessage.setFromUserId(this.getFromUserId());
        userMessage.setToUserId(this.getToUserId());
        userMessage.setPostId(this.getPostId());
        userMessage.setCommentId(this.getCommentId());
        userMessage.setContent(this.getContent());
        userMessage.setMessageType(this.getMessageType());
        userMessage.setCreated(this.getCreated());
        userMessage.setModified(this.getModified());
        userMessage.setStatus(this.getStatus());
        return userMessage;
    }

    public UserMessage toInsertEntity(){
        UserMessage userMessage = this.toUserMessage();
        userMessage.setId(null);
        userMessage.setCreated(new Date());
        userMessage.setModified(new Date());
        userMessage.setStatus(UserMessageStatus.unread);
        return userMessage;
    }



}
